'''
关于赋值、深拷贝、浅拷贝
赋值：复制指针
不可变数据类型：
    深浅拷贝都是赋值引用，因为不可变变量本身是无法修改值的
可变数据类型：
    浅拷贝：
        1、正确复制第一层内容，单独开辟空间，如果第一层内容变化，浅拷贝的变量仍然是正确的
        2、第二层内容（只涉及可变数据类型）只复制指针。
    深拷贝：
        1、正确复制所有层内容，单独开辟空间
不可变嵌套可变
    浅拷贝：拷贝引用关系
    深拷贝：其中的可变数据都开辟空间进行拷贝
可变嵌套不可变
    浅拷贝：无影响，拷贝一层
    深拷贝：深拷贝也只拷贝不可变的指针
注：
    对于不可变数据类型，深拷贝，浅拷贝，都只是拷贝指针，因为不可变变量本身无法修改内容。
    切片算浅拷贝
    list2 = list(list1)也算浅拷贝
'''

# 列表
import copy

bicycles = ["trek", "cannondale", "redline", "specialized"]
print(bicycles)

# 访问列表元素
print(bicycles[0])
print(bicycles[2].title())
print(bicycles[-1])

# 值的使用
print(f"My first bicycle was a {bicycles[3].title()}")

# 修改、添加和删除元素
## 修改 motorcycles[0] = "ducati"
motorcycles = ["honda", "yamaha", "suzuki"]
print(motorcycles)
motorcycles[0] = "ducati"
print(motorcycles)

# 添加
## 末尾添加 motorcycles.append("ducati")
motorcycles = ["honda", "yamaha", "suzuki"]
print(f"motorcycles: {motorcycles}")
motorcycles.append("ducati")
print(motorcycles)

motorcycles = []
motorcycles.append("honda")
motorcycles.append("yamaha")
motorcycles.append("suzuki")
print(motorcycles)

## 列表插入元素 motorcycles.insert(0, "ducati")
motorcycles = ["honda", "yamaha", "suzuki"]
motorcycles.insert(0, "ducati")
print(motorcycles)

# 删除
## del删除 del motorcycles[0]
motorcycles = ["honda", "yamaha", "suzuki"]
print(motorcycles)
del motorcycles[0]
print(motorcycles)

motorcycles.insert(0,"honda")
print(motorcycles)
del motorcycles[1]
print(motorcycles)


## 使用 pop（）删除 motorcycles.pop()
motorcycles = ["honda", "yamaha", "suzuki"]
print("aaaaa")
print(motorcycles)
popped_motorcycle = motorcycles.pop()
print(popped_motorcycle)
print(motorcycles)

## pop()删除任意位置元素 motorcycles.pop(0)
motorcycles = ["honda","yamaha","suzuki"]
print(motorcycles)
first_owned = motorcycles.pop(0)
print(f"The first motorcycle i owned was a {first_owned.title()} {motorcycles.pop(0)}")
print(motorcycles)
motorcycles.pop(0)
print(motorcycles)

## 根据值删除  motorcycles.remove("value")
motorcycles = ["honda","yamaha","suzuki","ducati","ducati"]
print(motorcycles)
motorcycles.remove("ducati") #只能删除一次
print(motorcycles)
too_expensive = "ducati"
motorcycles.remove(too_expensive)
print(motorcycles)
print(f"\nA {too_expensive.title()} is too expensive for me")

# 管理列表
## 使用 sort()进行永久排序
cars = ["bmw","bmwa","audi", "toyota", "subaru"]
print(cars)
cars.sort()
print(cars)
cars.sort(reverse=True)
print(cars)

## 使用sorted()进行临时排序
cars = ["bmw", "audi", "toyota", "subaru"]
print(f"Here is the original list:\n{cars}")
print(sorted(cars))
print(cars)

## 反向打印列表 car.reverse()
cars = ["bmw", "audi", "toyota", "subaru"]
print(cars)
cars.reverse()
print(cars)

## 确定列表长度len()
cars = ["bmw", "audi", "toyota", "subaru"]
print(cars)
print(len(cars))

# 其他
a = ["a","b",["c"]]
b = copy.copy(a)
c = copy.deepcopy(a)
d = a
print(a)
print(b)
print(c)
print(d)
a.append("c")
print(a)
print(b)
print(c)
print(d)
a[2].append("d")
print(a)
print(b)
print(c)
print(d)

